using Indiefreaks.Xna.Core;
using Indiefreaks.Xna.Rendering;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Indiefreaks.AceOnSteroids.Layers
{
    /// <summary>
    /// Class responsible of rendering the Indiefreaks Studio Splash Screen
    /// Automatically loads the background texture when added to GameState
    /// </summary>
    public class IndiefreaksSplashScreen : Layer, IContentHost
    {
        private Texture2D _backgroundTexture;
        private SpriteBatch _spriteBatch;
        private Rectangle _viewportRectangle;

        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="gameState">The GameState this layer is added to</param>
        public IndiefreaksSplashScreen(GameState gameState) : base(gameState)
        {
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            _spriteBatch.Begin();

            _spriteBatch.Draw(_backgroundTexture, _viewportRectangle, Color.White);

            _spriteBatch.End();
        }

        #region Implementation of IContentHost

        public void LoadContent(IContentCatalogue catalogue, ContentManager manager)
        {
            // we retrieve the GraphicsDevice instance from the static GraphicsDeviceManager property found in the Application class
            GraphicsDevice graphicsDevice = Application.Graphics.GraphicsDevice;

            _spriteBatch = new SpriteBatch(graphicsDevice);

            _backgroundTexture = manager.Load<Texture2D>("Textures/IndiefreaksStudioSplashScreen");

            _viewportRectangle = graphicsDevice.Viewport.Bounds;
        }

        public void UnloadContent(IContentCatalogue catalogue)
        {
        }

        #endregion
    }
}